package com.jx.gocomtask;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@SpringBootApplication
@EnableSwagger2
public class Application {
	public static void main(String[] args) {
		//SpringApplication.run(Application.class, args);
		SpringApplication springApplication=new SpringApplication(Application.class);
		springApplication.addListeners(new ApplicationStartup());
		springApplication.run(args);
	}
	 @Bean
	    public Docket createRestApi() {
	        return new Docket(DocumentationType.SWAGGER_2)
	                .apiInfo(new ApiInfoBuilder()
	                        .title("引擎服务 APIs")
	                        .description("")
	                        .version("1.0")
	                        .build())
	                //.pathMapping("/api")
	                .select()
	                .apis(RequestHandlerSelectors.basePackage("com.jx.gocomtask.webservice.restcontroller"))
	               .paths(PathSelectors.any())
	                .build();
	    }
	 @Value("${gocom.api.superapp.appid}")
		String appid = "supu3fg612wtd";
		@Value("${gocom.api.superapp.secret}")
		String secret = "1uj2mte5--";
		@Value("${gocom.api.superapp.defaultappid}")
		String defaultappid = "xw7snhdayl--";
		@Value("${gocom.api.superapp.defaultgroupappid}")
		String  defaultgroupappid="grpifp5o6wq3z1==";
		@Value("${gocom.api.superapp.apiurl}")
		String apiUrl = "http://172.20.95.11:9901/gocomapi/rest/";
		@Value("${gocom.api.service.url}")
		String serviceUrl = "http://172.20.54.12:13000/?token=%token%";
		@Value("${gocom.api.service.ios}")
		String serviceIosUrl = "http://172.20.54.12:13000/?token=%token%";
		@Value("${gocom.api.service.android}")
		String serviceAndroidUrl = "http://172.20.54.12:13000/?token=%token%";
		
		@Value("${gocom.api.service.menu.todo}")
		String menuTodo = "http://172.20.95.36/tools/lighttask/?token=%token%%";
		@Value("${gocom.api.service.menu.view}")
		String menuView = "http://172.20.95.36/tools/lighttask/?token=%token%";
		@Value("${gocom.api.service.menu.list}")
		String menuList = "http://172.20.95.36/tools/lighttask/?token=%token%";
		@Value("${gocom.api.service.page.todoCount}")
		String  todoCount="";
		@Value("${gocom.api.service.page.taskDetails}")
		String  taskDetails="";
		@Bean("taskDetails")
		public String taskDetails() {
			return taskDetails;
		}
		@Bean("todoCount")
		public String todoCount() {
			return todoCount;
		}
		@Bean("menuTodo")
		public String menuTodo() {
			return menuTodo;
		}
		
		@Bean("menuView")
		public String menuView() {
			return menuView;
		}
		
		@Bean("menuList")
		public String menuList() {
			return menuList;
		}
		
		@Bean("apiurl")
		public String gocomeApiUrl() {
			return apiUrl;
		}
		@Bean("serviceUrl")
		public String gocomeServiceUrl() {
			return serviceUrl;
		}
		@Bean("serviceIosUrl")
		public String gocomeServiceIosUrl() {
			return serviceIosUrl;
		}
		@Bean("serviceAndroidUrl")
		public String gocomeServiceAndroidUrl() {
			return serviceAndroidUrl;
		}
		@Bean("defaultAppId")
		public String defaultAppId() {
			return defaultappid;
		}
		
		@Bean("defaultGroupAppId")
		public String defaultGroupAppId() {
			return defaultgroupappid;
		}
		
		@Bean
		public MultiValueMap<String, String> superappConfig() {
			MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
			requestEntity.add("appid", appid);
			requestEntity.add("secret", secret);
			return requestEntity;
		}
		@Bean
		public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
			return new PropertySourcesPlaceholderConfigurer();
		}
		@Bean
		public RestTemplate restTemplate(RestTemplateBuilder builder) {
			return builder.build();
		}
}